﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using TrenchcoatRobots.Datatypes.States;
using TrenchcoatRobots.Datatypes;

namespace TrenchcoatRobots.Classes.ComponentClasses {
	class PhysicsObject : Component {
		public Vector2 Velocity { get; set; }
		public float Restitution { get; set; }
		public float Drag { get; set; }

		public PhysicsObject( ParentMethod gameObjectMethod, float drag, float restitution )
			: base( gameObjectMethod, "Physics Object", false ) {
			Velocity = new Vector2();
			Drag = drag;
			Restitution = restitution;
		}

		public override void Update( ref GameTime gameTime ) {
            Velocity += PhysicsState.Gravity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            Velocity -= Velocity * Drag * (float)gameTime.ElapsedGameTime.TotalSeconds;

			base.Parent().Position += Velocity;
		}

		public override void Collided( GameObject otherCopy, CollisionInfo collisionInformation ) {
			Velocity = -Vector2.Reflect(Velocity,collisionInformation.Normal) * Restitution;
		}
	}
}
